package org.learn.intermediate.homework;

import java.util.ArrayList;
import java.util.Iterator;

public class HomeWork12 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        Car1 car1 = new Car1("宝马", 20000);
        Car1 car2 = new Car1("宾利", 30000);
        //
        arrayList.add(car1);
        arrayList.add(car2);
        System.out.println(arrayList);
        //
        arrayList.remove(car1);
        System.out.println(arrayList);
        //
        System.out.println(arrayList.contains(car1));
        //
        System.out.println(arrayList.size());
        //
        System.out.println(arrayList.isEmpty());
        //\
//        arrayList.clear();
        //
       arrayList.addAll(arrayList);
        System.out.println(arrayList);
        //查找多个元素是否都存在
        arrayList.containsAll(arrayList);
        //
//        arrayList.removeAll(arrayList);
//        System.out.println(arrayList);

        //for
        for (Object o : arrayList) {
            System.out.println(o);
        }
        System.out.println();
        //
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(  next);
        }

    }
}
class Car1 {
    private String name;
    private double price;

    public Car1(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car1{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}
